var paramTable;
$(function(){	
	 $("#"+tabId+" #sdate").datetimepicker({
		   format: "yyyy-mm",
		   autoclose: true,
		   todayBtn: true,
		   minView: 3,
		   startView:3,
		   language: 'zh-CN'
	});
	$("#"+tabId+" #edate").datetimepicker({
		   format: "yyyy-mm",
		   autoclose: true,
		   todayBtn: true,
		   minView: 3,
		   startView:3,
		   language: 'zh-CN'
	});
	$("#"+tabId+" #forecastYear").datetimepicker({
		   format: "yyyy",
		   autoclose: true,
		   minView: 4,
		   startView:4,
		   language: 'zh-CN'
		});
	$('#'+tabId+' #sdate').val(drgsDate.dateFrom);
	$('#'+tabId+' #edate').val(drgsDate.dateTo);
	var forecastYear=Number(drgsDate.dateTo.substring(0, 4))+1;
	$("#"+tabId+" #forecastYear").val(forecastYear);
	//点击查询预算数据
	$("#"+tabId+" #search_png").click(function(){
		searchQuotaComputer(forecastYear);
	});
	$("#"+tabId+" #forecastYear").change(function(){
		forecastYear=$(this).val();
	});
	$("#"+tabId+" #search_png").click();
	//开始测算
	$("#" + tabId + " #calculate_btn").click(function() {
		quotaComputer(forecastYear);
	});
	//保存结果和获取上次测算数据
	saveForeCastResult();
	 //批量修改事件
	$("#"+tabId+" #mergeParamOk").click(function(){
		$("#paramDepGroup-table tbody").find("tr").each(function(i, n){
				if($("#"+tabId+" #paramQuotaCheck").val()=="AvgDays"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(2).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(3).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
				if($("#"+tabId+" #paramQuotaCheck").val()=="AvgFee"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(4).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(5).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
				if($("#"+tabId+" #paramQuotaCheck").val()=="AvgDrugFee"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(6).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(7).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}

				if($("#"+tabId+" #paramQuotaCheck").val()=="AvgDrugMateFee"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(8).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(9).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
				if($("#"+tabId+" #paramQuotaCheck").val()=="HCAvgFee"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(10).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(11).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
				if($("#"+tabId+" #paramQuotaCheck").val()=="HCAvgDrugFee"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(12).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(13).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
				if($("#"+tabId+" #paramQuotaCheck").val()=="HCAvgDrugMateFee"){
					if($("#"+tabId+" input[name='checkAll']:checked").val()==1 || ($("#"+tabId+" input[name='checkAll']:checked").val()==0 && $(n).find("td").eq(0).find("input[type='checkbox']").is(':checked'))){
						$(n).find("td").eq(14).find("input").attr("value",$("#"+tabId+" #overManageID").val());
						$(n).find("td").eq(15).find("input").attr("value",$("#"+tabId+" #notOverManageID").val());
					}
				}
		})
	});
	
});
/**
 * @ Discription:保存绩效
 * @Autor ：liuhongjun
 * @Date  ：2018年3月17日下午9:19:37
 */
function saveToQuotamanage(tpye){
	$.post(contextPath+"/ForeCast/saveToQuotamanage.dhc",{
		stdType:tpye,
		saveType:"I",
		forecastYear:$('#'+tabId+' #forecastYear').val()
	}).done(function(result){
		if(result.success){
			drgUI.success("成功保存为绩效标杆！");
		}else{
			drgUI.error("保存为绩效标杆失败！");
		}
	});
}
//跳转科室参数设置页面
function goToDepParam(depGroupCode, depGroupDesc){
	var str = "";
	var forecastYear=$('#'+tabId+' #forecastYear').val();
	$("#"+tabId+" #paramDepGroup-table tbody").find("tr").each(function(i, n){
		var depGroupCodes=$(n).find("td").eq(2).find("input").attr("id")?$(n).find("td").eq(2).find("input").attr("id").split("_")[0]:"";
		if(depGroupCodes==depGroupCode){
			var avgDaysL = $(n).find("td").eq(2).find("input").val();
			var avgDaysH = $(n).find("td").eq(3).find("input").val();
			str += "AvgDays:" + avgDaysL + ":" + avgDaysH;
			str += "-";
			var avgFeeL = $(n).find("td").eq(4).find("input").val();
			var avgFeeH = $(n).find("td").eq(5).find("input").val();
			str += "AvgFee:" + avgFeeL + ":" + avgFeeH;
			str += "-";
			var drugFeeL = $(n).find("td").eq(6).find("input").val();
			var drugFeeH = $(n).find("td").eq(7).find("input").val();
			str += "AvgDrugFee:" + drugFeeL + ":" + drugFeeH;
			str += "-";
			var drugMateFeeL =$(n).find("td").eq(8).find("input").val();
			var drugMateFeeH = $(n).find("td").eq(9).find("input").val();
			str += "AvgDrugMateFee:" + drugMateFeeL + ":" + drugMateFeeH;
			str += "-";
			str += "HCAvgFee:" + $(n).find("td").eq(10).find("input").val() + ":" + $(n).find("td").eq(11).find("input").val();
			str += "-";
			str += "HCAvgDrugFee:" + $(n).find("td").eq(12).find("input").val() + ":" + $(n).find("td").eq(13).find("input").val();
			str += "-";
			str += "HCAvgDrugMateFee:" + $(n).find("td").eq(14).find("input").val() + ":" + $(n).find("td").eq(15).find("input").val();
			str += ",";
		}
	});
	str = str.substr(0, str.length-1)
	openTab('/pages/yibao/quotaComputer/yibaoForecastDep.jsp', depGroupDesc + "|科室参数配置", 'forecastParamDep' + depGroupCode, 'forecastParamDep' + depGroupCode, {
		depGroupCode : depGroupCode,
		param : str,
		dateFrom : $("#" + tabId + " #sdate").val(),
		dateTo : $("#" + tabId + " #edate").val(),
		depGroupDesc : depGroupDesc,
		forecastYear : $('#'+tabId+' #forecastYear').val()
	});
}
//选择理想值、预测值 事件
function queryBytype(){
	var dateFrom = $("#"+tabId+" #sdate").val();
	var dateTo = $("#"+tabId+" #edate").val();
	
    //后台获取数据并加载
		$.post(contextPath+"/ForeCast/getLastResultHosp.dhc", {saveType: "I",stdYear:$('#'+tabId+' #forecastYear').val()})
		.done(function(result){
			var data = result.data;
			if(data){
				loadResultTableHosp(data);
			}else{
				emptyResultTableHosp();//清空全院数据	
			}
		});
		$.post(contextPath+"/ForeCast/getLastResultDepGroup.dhc", {saveType: "I",stdYear:$('#'+tabId+' #forecastYear').val()})
		.done(function(result){
			var data = result.data;
			if(data){
				loadResultTableDepGroup(data);
			}else{
				emptyResultTable();//清空科室组数据	

			}
		});	
		//获取科室上次预测的数据
		$.post(contextPath+"/ForeCast/getLastResultDep.dhc", {saveType: "I",stdYear:$('#'+tabId+' #forecastYear').val()})
		.done(function(result){
			var data = result.data;
			if(data){
				loadResultTableDep(data);
			}
		});
		
	}
/**
 * @ Discription:点击查询获取数据
 * @Autor ：liuhongjun
 * @Date  ：2018年3月15日上午9:31:35
 */
function searchQuotaComputer(forecastYear){
	var dateFrom = $("#"+tabId+" #sdate").val();
	var dateTo = $("#"+tabId+" #edate").val();
	$("#"+tabId+" #date-from").html(dateFrom);
	$("#"+tabId+" #date-to").html(dateTo);
	//全院预算数据
	$.post(contextPath+"/DrgsIndexCal/indexCal.dhc", {
		'dateFrom':dateFrom,
		'dateTo':dateTo,
		'quotaCode':"ForeCast",
		'monitorType':"hosp",
		'msCode':"std_computer",
		'hospCode':paramTabPage[tabId].hospCode,
		'compareType':"std"
	}).done(function(result){
		//科室组预算数据及标杆
		$.post(contextPath+"/DrgsIndexCal/indexCal.dhc", {
			'dateFrom':dateFrom,
			'dateTo':dateTo,
			'quotaCode':"ForeCast",
			'monitorType':"depGroup",
			'compareType':"std",
			'hospCode':paramTabPage[tabId].hospCode,
			'msCode':"std_computer"
		}).done(function(result_1){
			var data = [];
			var hospData={};
			if(result.data && result.data.length>0){
				hospData = result.data[0];
				data.push(hospData);
			}
			if(result_1.data && result_1.data.length>0){
				data = data.concat(result_1.data);
			}
			var columns = [{ "data": 'ddesc1', 
		                       "render": function(obj, type, full) {
		                    	   var ddesc = full.ddesc;
		                    	   if(ddesc=="全院"){
		                    		   return ddesc;
		                    	   }
		                    	   return "<a href=\"javascript:goToDepParam('"+full.ccode+"', '"+full.ddesc+"')\">"+full.ddesc+"</a>";
		                       }	 
		                     },
		                     { "data": 'TotalCaseCnt'},
		                     { "data": 'HCTotalCaseCnt'},
		                     { "data": 'HCTotalFund'},
		                     { "data": 'AvgDays'},
		                     { "data": 'AvgDayscc'},
		                     { "data": 'AvgFee'},
		                     { "data": 'AvgFeecc'},
		                     { "data": 'AvgDrugFee'},
		                     { "data": 'AvgDrugFeecc'},
		                     { "data": 'AvgDrugMateFee'},
		                     { "data": 'AvgDrugMateFeecc'},
		                     { "data": 'HCAvgFee'},
		                     { "data": 'HCAvgFeecc'},
		                     { "data": 'HCAvgDrugFee'},
		                     { "data": 'HCAvgDrugFeecc'},
		                     { "data": 'HCAvgDrugMateFee'},
		                     { "data": 'HCAvgDrugMateFeecc'}];
			
			var  paramDatatable = {lengthChange:false, info:false, searching:false, order:[[ 1, "desc" ]]};
			$("#"+tabId+" #foredata-table").dataTableBasic(columns, data, paramDatatable);
			
			$("#"+tabId+" #hospAvgDays tr:eq(3)").find("td").eq(0).html(hospData.AvgDays);
			$("#"+tabId+" #hospAvgFee tr:eq(3)").find("td").eq(0).html(hospData.AvgFee);
			$("#"+tabId+" #hospHCTotalFund tr:eq(3)").find("td").eq(0).html(hospData.HCTotalFund);
			$("#"+tabId+" #hospDrugFee tr:eq(3)").find("td").eq(0).html(hospData.AvgDrugFee);
			$("#"+tabId+" #hospHCAvgFee tr:eq(3)").find("td").eq(0).html(hospData.HCAvgFee);
			$("#"+tabId+" #hospHCDrugFee tr:eq(3)").find("td").eq(0).html(hospData.HCAvgDrugFee);
			$("#"+tabId+" #hospTotalCaseCnt tr:eq(3)").find("td").eq(0).html(hospData.TotalCaseCnt);
			$("#"+tabId+" #hospHCCaseCnt tr:eq(3)").find("td").eq(0).html(hospData.HCTotalCaseCnt);
			$("#"+tabId+" #hospTotalCaseCnt tr:eq(3)").find("td").eq(0).html(hospData.TotalCaseCnt);
			$("#"+tabId+" #hospHCCaseCnt tr:eq(3)").find("td").eq(0).html(hospData.HCTotalCaseCnt);
			$("#"+tabId+" #hospTimeEff tr:eq(3)").find("td").eq(0).html(hospData.TimeEff);
			$("#"+tabId+" #hospFeeEff tr:eq(3)").find("td").eq(0).html(hospData.FeeEff);
			$("#"+tabId+" #hospDrugMateFee tr:eq(3)").find("td").eq(0).html(hospData.AvgDrugMateFee);
			$("#"+tabId+" #hospHCDrugMateFee tr:eq(3)").find("td").eq(0).html(hospData.HCAvgDrugMateFee);
			$("#"+tabId+" #hospTimeEff tr:eq(3)").find("td").eq(0).html(hospData.TimeEff);
			$("#"+tabId+" #hospFeeEff tr:eq(3)").find("td").eq(0).html(hospData.FeeEff);
			$("#"+tabId+" #hospCMI tr:eq(3)").find("td").eq(0).html(hospData.CMI);
		});
	});
	//获取上次保存的调整参数
	$.post(contextPath+ "/ForeCast/findDepGroupForeCast.dhc",{
		'dateFrom' : dateFrom,
		'dateTo' : dateTo,
		'forecastYear': $('#'+tabId+' #forecastYear').val(),
		'monitorType': "depGroup"
	}).done(function(result) {
		var columns = [ {
			"data" : 'depGroupDesc1',
			"render" : function(obj, type, full) {
				return "<input type='checkbox' />  <a href=\"javascript:goToDepParam('" + full.depGroupCode + "', '" + full.depGroupDesc + "')\">" + full.depGroupDesc + "</a>";
			}
		}, {
			"data" : 'TotalCaseCnt'
		}, {
			"data" : "AvgDaysL1",
			"render" : function(obj, type, full) {
				var avgDaysL = full.AvgDaysL ? full.AvgDaysL : 0;
				return "<input id='" + full.depGroupCode + "_AvgDaysL' type='text' style='width:50px' value='" + avgDaysL + "'></input>";
			}
		}, {
			"data" : "AvgDaysH1",
			"render" : function(obj, type, full) {
				var avgDaysH = full.AvgDaysH ? full.AvgDaysH : 0;
				return "<input id='" + full.depGroupCode + "_AvgDaysH' type='text' style='width:50px' value='" + avgDaysH + "'></input>";
			}
		}, {
			"data" : "AvgFeeL1",
			"render" : function(obj, type, full) {
				var avgFeeL = full.AvgFeeL ? full.AvgFeeL : 0;
				return "<input id='" + full.depGroupCode + "_AvgFeeL' type='text' style='width:50px' value='" + avgFeeL + "'></input>";
			}
		}, {
			"data" : "AvgFeeH1",
			"render" : function(obj, type, full) {
				var avgFeeH = full.AvgFeeH ? full.AvgFeeH : 0;
				return "<input id='" + full.depGroupCode + "_AvgFeeH' type='text' style='width:50px' value='" + avgFeeH + "'></input>";
			}
		},

		{
			"data" : "AvgDrugFeeL1",
			"render" : function(obj, type, full) {
				var drugFeeL = full.AvgDrugFeeL ? full.AvgDrugFeeL : 0;
				return "<input id='" + full.depGroupCode + "_AvgDrugFeeL' type='text' style='width:50px' value='" + drugFeeL + "'></input>";
			}
		}, {
			"data" : "AvgDrugFeeH1",
			"render" : function(obj, type, full) {
				var drugFeeH = full.AvgDrugFeeH ? full.AvgDrugFeeH : 0;
				return "<input id='" + full.depGroupCode + "_AvgDrugFeeH' type='text' style='width:50px' value='" + drugFeeH + "'></input>";
			}
		},

		{
			"data" : "AvgDrugMateFeeL1",
			"render" : function(obj, type, full) {
				var drugMateFeeL = full.AvgDrugMateFeeL ? full.AvgDrugMateFeeL : 0;
				return "<input id='" + full.depGroupCode + "_AvgDrugMateFeeL' type='text' style='width:50px' value='" + drugMateFeeL + "'></input>";
			}
		}, {
			"data" : "AvgDrugMateFeeH2",
			"render" : function(obj, type, full) {
				var drugMateFeeH = full.AvgDrugMateFeeH ? full.AvgDrugMateFeeH : 0;
				return "<input id='" + full.depGroupCode + "_AvgDrugMateFeeH' type='text' style='width:50px' value='" + drugMateFeeH + "'></input>";
			}
		} ,{
			"data" : "HCAvgFeeL1",
			"render" : function(obj, type, full) {
				var hcvalue = full.HCAvgFeeL ? full.HCAvgFeeL : 0;
				return "<input id='" + full.depGroupCode + "_HCAvgFeeL' type='text' style='width:50px' value='" + hcvalue + "'></input>";
			}
		}, {
			"data" : "HCAvgFeeH2",
			"render" : function(obj, type, full) {
				var hcvalue = full.HCAvgFeeH ? full.HCAvgFeeH: 0;
				return "<input id='" + full.depGroupCode + "_HCAvgFeeH' type='text' style='width:50px' value='" + hcvalue + "'></input>";
			}
		},
		{
			"data" : "HCAvgDrugFeeL1",
			"render" : function(obj, type, full) {
				var hcvalue = full.HCAvgDrugFeeL ? full.HCAvgDrugFeeL : 0;
				return "<input id='" + full.depGroupCode + "_HCAvgDrugFeeL' type='text' style='width:50px' value='" + hcvalue + "'></input>";
			}
		}, {
			"data" : "HCAvgDrugFeeH2",
			"render" : function(obj, type, full) {
				var hcvalue = full.HCAvgDrugFeeH ? full.HCAvgDrugFeeLH : 0;
				return "<input id='" + full.depGroupCode + "_HCAvgDrugFeeH' type='text' style='width:50px' value='" + hcvalue + "'></input>";
			}
		},
		{
			"data" : "HCAvgDrugMateFeeL1",
			"render" : function(obj, type, full) {
				var hcvalue = full.HCAvgDrugMateFeeL ? full.HCAvgDrugMateFeeL : 0;
				return "<input id='" + full.depGroupCode + "_HCAvgDrugMateFeeL' type='text' style='width:50px' value='" + hcvalue + "'></input>";
			}
		}, {
			"data" : "HCAvgDrugMateFeeH2",
			"render" : function(obj, type, full) {
				var hcvalue = full.HCAvgDrugMateFeeH ? full.HCAvgDrugMateFeeH : 0;
				return "<input id='" + full.depGroupCode + "_HCAvgDrugMateFeeH' type='text' style='width:50px' value='" + hcvalue + "'></input>";
			}
		}];

		var paramDatatable = {
			lengthChange : false,
			info : false,
			searching : false,
			order : [ [ 1, "desc" ] ],
			paging : false,
			scrollX : false,
			scrollY : 320
		};
		var data = [];
		if (result.success && result.data && result.data.length > 0) {
			data = result.data;
		}
		paramTable = $("#" + tabId + " #paramDepGroup-table").dataTableBasic(columns, data, paramDatatable);
	});
}
/**
 * @ Discription:开始测算
 * @Autor ：liuhongjun
 * @Date ：2018年3月15日上午9:36:52
 */
function quotaComputer(forecastYear){
	$('#'+tabId+' #processId').css('display','block');
	var dateFrom = $("#" + tabId + " #sdate").val();
	var dateTo = $("#" + tabId + " #edate").val();
	$("#" + tabId + " #calculate_btn").attr("disabled", "");
	$("#" + tabId + " #calculate_btn").html("正在测算");
	$('#' + tabId + ' #total1').html('0%');
	$('#' + tabId + ' #total1').css('width', '0%');
	$("#" + tabId + " #processInfo").html("正在保存参数");
	$('#' + tabId + '#processId').fadeIn(500);
	var str = "";
	var rows = paramTable.columns().context[0].aoData;
	$.each(rows, function(i, n) {
		n = n.anCells;
		var depGroupCode = $(n[2]).find("input").attr("id") ? $(n[2]).find("input").attr("id").split("_")[0] : "";
		str += depGroupCode + "|";
		var avgDaysL = $(n[2]).find("input").val();
		var avgDaysH = $(n[3]).find("input").val();
		str += "AvgDays:" + avgDaysL + ":" + avgDaysH;
		str += "-";
		var avgFeeL = $(n[4]).find("input").val();
		var avgFeeH = $(n[5]).find("input").val();
		str += "AvgFee:" + avgFeeL + ":" + avgFeeH;
		str += "-";
		var drugFeeL = $(n[6]).find("input").val();
		var drugFeeH = $(n[7]).find("input").val();
		str += "AvgDrugFee:" + drugFeeL + ":" + drugFeeH;
		str += "-";
		var drugMateFeeL = $(n[8]).find("input").val();
		var drugMateFeeH = $(n[9]).find("input").val();
		str += "AvgDrugMateFee:" + drugMateFeeL + ":" + drugMateFeeH;
		
		str += "-";
		var HCAvgFeeL = $(n[10]).find("input").val();
		var HCAvgFeeH = $(n[11]).find("input").val();
		str += "HCAvgFee:" + HCAvgFeeL + ":" + HCAvgFeeH;
		
		str += "-";
		var HCAvgDrugFeeL = $(n[12]).find("input").val();
		var HCAvgDrugFeeH = $(n[13]).find("input").val();
		str += "HCAvgDrugFee:" + HCAvgDrugFeeL + ":" + HCAvgDrugFeeH;
		
		str += "-";
		var HCAvgDrugMateFeeL = $(n[14]).find("input").val();
		var HCAvgDrugMateFeeH = $(n[15]).find("input").val();
		str += "HCAvgDrugMateFee:" + HCAvgDrugMateFeeL + ":" + HCAvgDrugMateFeeH;
		str += ",";
	})
	str = str.substr(0, str.length - 1)
	// 测算方法关键代码, 见后台
	$.post(contextPath + "/ForeCast/quotasComputer.dhc", {
		'adjustParameter' : str,
		'dateFrom' : dateFrom,
		'dateTo' : dateTo,
		'forecastYear' : $('#'+tabId+' #forecastYear').val(),
		'hospCode':paramTabPage[tabId].hospCode,
		'monitorType': "depGroup"
	}).done(function(result) {
		var data = result.data;
		var dataDep = data.dep;
		var dataDepGroup = data.depGroup;
		var dataHosp = data.hosp;
		loadResultTableHosp(dataHosp);
		loadResultTableDepGroup(dataDepGroup);
		loadResultTableDep(dataDep);
		
		$("#processInfo").html("测算完成");
		$('#processId').fadeOut("slow");
		$("#calculate_btn").removeAttr("disabled");
		$("#calculate_btn").html("开始测算");
		$('#'+tabId+' #processId').css('display','none');
	});
	// 进度条
//	var timerId = window.setInterval(function() {
//		$.post(contextPath + "/ForeCast/getProcess.dhc").done(function(result) {
//			var data = result.data;
//			if (data) {
//				var total = data.total;
//				var current = data.currentDepCount ? data.currentDepCount : 0;
//				var percent11 = (parseFloat(current) / parseFloat(total)) * 98;
//				var currentDepName = data.currentDepName ? data.currentDepName : "";
//				$('#total1').html(percent11.toFixed(0) + '%');
//				$('#total1').css('width', percent11 + '%');
//				$("#processInfo").html(currentDepName);
//				if (data.states == "dis") {
//					$("#processInfo").html("正在汇总病种数据...");
//				}
//				if (data.states == "success") {
//					$('#total1').html('100%');
//					$('#total1').css('width', '100%');
//					window.clearInterval(timerId);
//					$("#processInfo").html("测算完成");
//					$('#processId').fadeOut("slow");
//					$("#calculate_btn").removeAttr("disabled");
//					$("#calculate_btn").html("开始测算");
//					$('#'+tabId+' #processId').css('display','none');
//				}
//			}
//		});
//	}, 1000);
}
/**
 * @ Discription:加载上次保存数据
 * @Autor ：liuhongjun
 * @Date  ：2018年3月15日下午3:39:10
 */
function saveForeCastResult() {
	var dateFrom = $("#" + tabId + " #sdate").val();
	var dateTo = $("#" + tabId + " #edate").val();
	var forecastYear = $('#' + tabId + ' #forecastYear').val();
	$("#editHosp_btn").click(function() {
		$(".editClass").each(function(i, n) {
			var value = $(n).html();
			if (value && value != "") {
				if ($(n).find("input").size() <= 0) {
					$(n).html('<input value="' + value + '"/>');
				}
			}
		})
	});
	/*保存全院指标测算结果*/
	$("#" + tabId + " #saveHosp_btn").on("click", function() {
		var str = "";
		str += "hosp|";
		$(".editClass").each(function(i, n) {
			if (i == 0) {
				str += "AvgDays:" + $(n).find('input').val()  + ",";
			} else if (i == 1) {
				str += "AvgFee:" + $(n).find('input').val() + ",";
			} else if (i == 2) {
				str += "AvgDrugFee:" + $(n).find('input').val()  + ",";
			} else if (i == 3) {
				str += "TotalCaseCnt:" + $(n).find('input').val() + ",";
			} else if (i == 4) {
				str += "TimeEff:" + $(n).find('input').val()  + ",";
			} else if (i == 5) {
				str += "FeeEff:" + $(n).find('input').val()  + ",";
			} else if (i == 6) {
				str += "AvgDrugMateFee:" + $(n).find('input').val() + ",";
			}else if (i==7){
				str += "HCAvgFee:" + $(n).find('input').val()  + ",";
			}else if (i==8){
				str += "HCAvgDrugFee:" + $(n).find('input').val()  + ",";
			}else if (i==9){
				str += "HCCaseCnt:" + $(n).find('input').val() + ",";
			}else if (i==10){
				str += "HCTotalFund:" + $(n).find('input').val() + ",";
			}else if (i==11){
				str += "HCAvgDrugMateFee:" + $(n).find('input').val() + ",";
			}else if (i==12){
				str += "CMI:" + $(n).find('input').val() + ",";
			}
		})
		str = str.substr(0, str.length - 1)
		$.post(contextPath + "/ForeCast/saveExpected.dhc", {
			quotaStr : str,
			saveType : "I",
			type : "hosp",
			forecastYear : $('#'+tabId+' #forecastYear').val(),
			dateFrom : dateFrom,
			dateTo : dateTo
		}).done(function(result) {
			if (result.success) {
				drgUI.confirm({
					content : '预测结果已保存，是否保存为绩效标杆？',
					callSure : function() {
						saveToQuotamanage("hosp");
					}
				})
			}
		});
	});
	/*保存科室组的测算结果*/
	$("#" + tabId + " #saveDepGroup_btn").on("click", function() {
		var trCnt=$("#resultDepGroup-table tbody").find("tr").size();
		var m=0;
		$("#resultDepGroup-table tbody").find("tr").each(function(i, n) {
			var str = "";
			var depGroupCode = $(n).find("td").eq(2).find("input").attr("id") ? $(n).find("td").eq(2).find("input").attr("id").split("_")[0] : "";
			str += depGroupCode + "|";
			var avgDays = $(n).find("td").eq(1).find("input").val();
			str += "AvgDays:" + avgDays + ",";
			var avgFee = $(n).find("td").eq(2).find("input").val();
			str += "AvgFee:" + avgFee + ",";
			var drugFee = $(n).find("td").eq(3).find("input").val();
			str += "AvgDrugFee:" + drugFee + ",";
			var totalCaseCnt = $(n).find("td").eq(4).find("input").val();
			str += "TotalCaseCnt:" + totalCaseCnt + ",";
			var timeEff = $(n).find("td").eq(5).find("input").val();
			str += "TimeEff:" + timeEff + ",";
			var feeEff = $(n).find("td").eq(6).find("input").val();
			str += "FeeEff:" + feeEff + ",";
			var drugMateFee = $(n).find("td").eq(7).find("input").val();
			str += "AvgDrugMateFee:" + drugMateFee + ",";
			str += "HCCaseCnt:" + $(n).find("td").eq(8).find("input").val() + ",";
			str += "NotHCRatio:" + $(n).find("td").eq(9).find("input").val() + ",";
			str += "HCTotalFund:" + $(n).find("td").eq(10).find("input").val() + ",";
			str += "HCAvgFee:" + $(n).find("td").eq(11).find("input").val() + ",";
			str += "HCAvgDrugFee:" + $(n).find("td").eq(12).find("input").val() + ",";
			str += "HCAvgDrugMateFee:" + $(n).find("td").eq(13).find("input").val() + ",";
			str += "CMI:" + $(n).find("td").eq(14).find("input").val() + ",";
			str = str.substr(0, str.length - 1)
			$.post(contextPath + "/ForeCast/saveExpected.dhc", {
				quotaStr : str,
				saveType : "I",
				type : "depGroup",
				forecastYear : $('#'+tabId+' #forecastYear').val(),
				dateFrom : dateFrom,
				dateTo : dateTo
			}).done(function(result) {
				if (!result.success) {
					drgUI.warning(depGroupCode + ":" + result.errorMessage);
					return false;
				}
				m++;
				if(m==trCnt){
					drgUI.confirm({
						content : '预测结果已保存，是否保存为绩效标杆？',
						callSure : function() {
							saveToQuotamanage("depGroup");
						}
					});
				}
			});
		});
	});
	/*保存科室的基本信息*/
	$("#" + tabId + " #saveDep_btn").on("click", function() {
		var trCnt=$("#resultDep-table tbody").find("tr").size();
		var m=0;
		$("#resultDep-table tbody").find("tr").each(function(i, n) {
			var str = "";
			var depCode = $(n).find("td").eq(2).find("input").attr("id") ? $(n).find("td").eq(2).find("input").attr("id").split("_")[0] : "";
			str += depCode + "|";
			var avgDays = $(n).find("td").eq(1).find("input").val();
			str += "AvgDays:" + avgDays + ",";
			var avgFee = $(n).find("td").eq(2).find("input").val();
			str += "AvgFee:" + avgFee + ",";
			var drugFee = $(n).find("td").eq(3).find("input").val();
			str += "AvgDrugFee:" + drugFee + ",";
			var totalCaseCnt = $(n).find("td").eq(4).find("input").val();
			str += "TotalCaseCnt:" + totalCaseCnt + ",";
			var timeEff = $(n).find("td").eq(5).find("input").val();
			str += "TimeEff:" + timeEff + ",";
			var feeEff = $(n).find("td").eq(6).find("input").val();
			str += "FeeEff:" + feeEff + ",";
			var drugMateFee = $(n).find("td").eq(7).find("input").val();
			str += "AvgDrugMateFee:" + drugMateFee + ",";
			str += "HCCaseCnt:" + $(n).find("td").eq(8).find("input").val() + ",";
			str += "NotHCRatio:" + $(n).find("td").eq(9).find("input").val() + ",";
			str += "HCTotalFund:" + $(n).find("td").eq(10).find("input").val() + ",";
			str += "HCAvgFee:" + $(n).find("td").eq(11).find("input").val() + ",";
			str += "HCAvgDrugFee:" + $(n).find("td").eq(12).find("input").val() + ",";
			str += "HCAvgDrugMateFee:" + $(n).find("td").eq(13).find("input").val() + ",";
			str += "CMI:" + $(n).find("td").eq(14).find("input").val() + ",";
			str = str.substr(0, str.length - 1)
			$.post(contextPath + "/ForeCast/saveExpected.dhc", {
				quotaStr : str,
				saveType : "I",
				type : "dep",
				forecastYear : $('#'+tabId+' #forecastYear').val(),
				dateFrom : dateFrom,
				dateTo : dateTo
			}).done(function(result) {
				if (!result.success) {
					drgUI.warning(depCode + ":" + result.errorMessage);
					return false;
				}
				m++;
				if(m==trCnt){
					drgUI.confirm({
						content : '预测结果已保存，是否保存为绩效标杆？',
						callSure : function() {
							saveToQuotamanage("dep");
						}
					});
				}
			});
		});
	});
/*
	$("#" + tabId + " #saveMDC_btn").unbind("click");
	$("#" + tabId + " #saveMDC_btn").bind("click", function() {
		$("#resultMDC-table tbody").find("tr").each(function(i, n) {
			var str = "";
			var mdcCode = $(n).find("td").eq(2).find("input").attr("id") ? $(n).find("td").eq(2).find("input").attr("id").split("_")[0] : "";
			str += mdcCode + "|";
			var avgDays = $(n).find("td").eq(1).find("input").val();
			str += "AvgDays:" + avgDays + ",";
			var avgFee = $(n).find("td").eq(2).find("input").val();
			str += "AvgFee:" + avgFee + ",";
			var hcAvgFee = $(n).find("td").eq(3).find("input").val();
			str += "HCAvgFee:" + hcAvgFee + ",";
			var drugFee = $(n).find("td").eq(4).find("input").val();
			str += "DrugFee:" + drugFee + ",";
			var hcDrugFee = $(n).find("td").eq(5).find("input").val();
			str += "HCDrugFee:" + hcDrugFee + ",";
			var totalCaseCnt = $(n).find("td").eq(6).find("input").val();
			str += "TotalCaseCnt:" + totalCaseCnt + ",";
			var hcCaseCnt = $(n).find("td").eq(7).find("input").val();
			str += "HCCaseCnt:" + hcCaseCnt + ",";
			var hcTotalFund = $(n).find("td").eq(9).find("input").val();
			str += "HCTotalFund:" + hcTotalFund + ",";
			var timeEff = $(n).find("td").eq(10).find("input").val();
			str += "TimeEff:" + timeEff + ",";
			var feeEff = $(n).find("td").eq(11).find("input").val();
			str += "FeeEff:" + feeEff + ",";
			str = str.substr(0, str.length - 1)
			$.post(contextPath + "/ForeCast/saveExpected.dhc", {
				type2 : str,
				parmdcCode : mdcCode,
				type1 : "I",
				forecastYear : $('#' + tabId + ' #forecastYear').val()
			}).done(function(result) {
				if (!result.success) {
					drgUI.warning(mdcCode + ":" + result.errorMessage);
					return false;
				}
				drgUI.success("保存完毕");
			});
		})
	});

	$("#" + tabId + " #saveADRG_btn").unbind("click")
	$("#" + tabId + " #saveADRG_btn").bind("click", function() {
		$("#resultADRG-table tbody").find("tr").each(function(i, n) {
			var str = "";
			var adrgCode = $(n).find("td").eq(2).find("input").attr("id") ? $(n).find("td").eq(2).find("input").attr("id").split("_")[0] : "";
			str += adrgCode + "|";
			var avgDays = $(n).find("td").eq(1).find("input").val();
			str += "AvgDays:" + avgDays + ",";
			var avgFee = $(n).find("td").eq(2).find("input").val();
			str += "AvgFee:" + avgFee + ",";
			var hcAvgFee = $(n).find("td").eq(3).find("input").val();
			str += "HCAvgFee:" + hcAvgFee + ",";
			var drugFee = $(n).find("td").eq(4).find("input").val();
			str += "DrugFee:" + drugFee + ",";
			var hcDrugFee = $(n).find("td").eq(5).find("input").val();
			str += "HCDrugFee:" + hcDrugFee + ",";
			var totalCaseCnt = $(n).find("td").eq(6).find("input").val();
			str += "TotalCaseCnt:" + totalCaseCnt + ",";
			var hcCaseCnt = $(n).find("td").eq(7).find("input").val();
			str += "HCCaseCnt:" + hcCaseCnt + ",";
			var hcTotalFund = $(n).find("td").eq(9).find("input").val();
			str += "HCTotalFund:" + hcTotalFund + ",";
			var timeEff = $(n).find("td").eq(10).find("input").val();
			str += "TimeEff:" + timeEff + ",";
			var feeEff = $(n).find("td").eq(11).find("input").val();
			str += "FeeEff:" + feeEff + ",";
			str = str.substr(0, str.length - 1)
			$.post(contextPath + "/ForeCast/saveExpected.dhc", {
				type2 : str,
				paradrgCode : adrgCode,
				type1 : "I"
			}).done(function(result) {
				if (!result.success) {
					drgUI.warning(adrgCode + ":" + result.errorMessage);
					return false;
				}
				drgUI.success("保存完毕");
			});
		})
	});

	$("#" + tabId + " #saveDRGs_btn").unbind("click");
	$("#" + tabId + " #saveDRGs_btn").bind("click", function() {
		$("#resultDRGs-table tbody").find("tr").each(function(i, n) {
			var str = "";
			var drgsCode = $(n).find("td").eq(2).find("input").attr("id") ? $(n).find("td").eq(2).find("input").attr("id").split("_")[0] : "";
			str += drgsCode + "|";
			var avgDays = $(n).find("td").eq(1).find("input").val();
			str += "AvgDays:" + avgDays + ",";
			var avgFee = $(n).find("td").eq(2).find("input").val();
			str += "AvgFee:" + avgFee + ",";
			var hcAvgFee = $(n).find("td").eq(3).find("input").val();
			str += "HCAvgFee:" + hcAvgFee + ",";
			var drugFee = $(n).find("td").eq(4).find("input").val();
			str += "DrugFee:" + drugFee + ",";
			var hcDrugFee = $(n).find("td").eq(5).find("input").val();
			str += "HCDrugFee:" + hcDrugFee + ",";
			var totalCaseCnt = $(n).find("td").eq(6).find("input").val();
			str += "TotalCaseCnt:" + totalCaseCnt + ",";
			var hcCaseCnt = $(n).find("td").eq(7).find("input").val();
			str += "HCCaseCnt:" + hcCaseCnt + ",";
			var hcTotalFund = $(n).find("td").eq(9).find("input").val();
			str += "HCTotalFund:" + hcTotalFund + ",";
			var timeEff = $(n).find("td").eq(10).find("input").val();
			str += "TimeEff:" + timeEff + ",";
			var feeEff = $(n).find("td").eq(11).find("input").val();
			str += "FeeEff:" + feeEff + ",";
			str = str.substr(0, str.length - 1)
			$.post(contextPath + "/ForeCast/saveExpected.dhc", {
				type2 : str,
				pardrgCode : drgsCode,
				type1 : "I"
			}).done(function(result) {
				if (!result.success) {
					drgUI.warning(drgsCode + ":" + result.errorMessage);
					return false;
				}
				drgUI.success("保存完毕");
			});
		})
	});*/

	$.post(contextPath + "/ForeCast/getLastResultHosp.dhc", {
		saveType : "I",
		stdYear : $('#'+tabId+' #forecastYear').val(),
		dateFrom : dateFrom,
		dateTo : dateTo

	}).done(function(result) {
		var data = result.data;
		if (data) {
			loadResultTableHosp(data);
		}
	});
	$.post(contextPath + "/ForeCast/getLastResultDepGroup.dhc", {
		saveType : "I",
		stdYear : $('#'+tabId+' #forecastYear').val(),
		dateFrom : dateFrom,
		dateTo : dateTo

	}).done(function(result) {
		var data = result.data;
		if (data) {
			loadResultTableDepGroup(data);
		}
	});

	// 获取科室上次预测的数据
	$.post(contextPath + "/ForeCast/getLastResultDep.dhc", {
		saveType : "I",
		stdYear : $('#'+tabId+' #forecastYear').val(),
		dateFrom : dateFrom,
		dateTo : dateTo
	}).done(function(result) {
		var data = result.data;
		if (data) {
			loadResultTableDep(data);
		}
	});

	// //获取MDC上次预测的数据
	// $.post(contextPath+"/ForeCast/getLastResultMDC.dhc", {dateFrom:dateFrom,
	// dateTo:dateTo, type1: "I"})
	// .done(function(result){
	// var data = result.data;
	// if(data){
	// loadResultTableMDC(data);
	//		}
	//	});
	//	
	//	//获取ADRG上次预测的数据
	//	$.post(contextPath+"/ForeCast/getLastResultADRG.dhc", {dateFrom:dateFrom, dateTo:dateTo, type1: "I"})
	//	.done(function(result){
	//		var data = result.data;
	//		if(data){
	//			loadResultTableAdrg(data);
	//		}
	//	});
	//	
	//	//获取ADRG上次预测的数据
	//	$.post(contextPath+"/ForeCast/getLastResultDRG.dhc", {dateFrom:dateFrom, dateTo:dateTo, type1: "I"})
	//	.done(function(result){
	//		var data = result.data;
	//		if(data){
	//			loadResultTableDrgs(data);
	//		}
	//	});

}